import type { ApplyBusiness, ApplyCashApprove, CashFlowEntityItem } from '@/types/business'
import type { userItem } from '@/types/member'
import { http } from '@/utils/http'
import { buildGetRequest } from '@/utils/utils'

/**
 * 商户申请
 * @param data 请求参数
 */
export const postBusinessAPI = (data: ApplyBusiness) => {
  return http({
    method: 'POST',
    url: '/admin/businessApi/applyBusiness',
    data,
  })
}

/**
 * 商户修改
 * @param data 请求参数
 */
export const putBusinessAPI = (data: ApplyBusiness) => {
  return http({
    method: 'PUT',
    url: '/admin/businessApi/updateBus',
    data,
  })
}

// 获取商户信息列表
export const getSearchBusUserListAPI = (str?: any) => {
  let urlStr = '/admin/businessApi/searchBusUserList'
  if (str) {
    urlStr = '/admin/businessApi/searchBusUserList' + str
  }
  return http<ApplyBusiness[]>({
    method: 'GET',
    url: urlStr,
  })
}

// 商户添加人员
export const postBusinessPeopleAPI = (data:any) => {
  return http({
    method: 'POST',
    url: '/admin/businessApi/addUserByRole',
    data,
  })
}

// 商户删除人员
export const delBusinessPeopleAPI = (data:any) => {
  return http({
    method: 'POST',
    url: '/admin/businessApi/deleteBusUserRole',
    data,
  })
}

// 获取用户自己的运营商信息
export const getBusinessInfoByUseridAPI = (id: string) => {
  return http<ApplyBusiness>({
    method: 'GET',
    url: `/admin/businessApi/userBusinessInfo?userId=${id}`,
  })
}

// 获取商户绑定的人员列表
export const getAppUserListByBusIdAPI = (roleCode: string, busId: string) => {
  return http<userItem[]>({
    method: 'GET',
    url: `/admin/businessApi/getAppUserListByBusId?roleCode=${roleCode}&busId=${busId}`,
  })
}

// 商户可提现金额
export const getBusinessCashApproveAmountAPI = (appUserId: string) => {
  return http({
    method: 'GET',
    url: `/admin/businessApi/busUserAmount?appUserId=${appUserId}`,
  })
}

// 商户提现
export const postBusinessCashApproveAPI = (userId: string, cashPrice:string, openId: string) => {
  return http({
    method: 'POST',
    url: `/admin/consumer/userCashApprove?userId=${userId}&cashPrice=${cashPrice}&openId=${openId}`,
    data: {
      userId: userId,
      cashPrice: cashPrice,
    },
  })
}
// 商户提现列表
export const postUserCashApproveListAPI = (appUserId: string) => {
  return http({
    method: 'GET',
    url: `/admin/consumer/userCashApproveList?appUserId=${appUserId}`,
  })
}
/**
 * 商户交易列表
 * 流水类型(多个用,分割):1-商家佣金;2-中奖返金;3-平台佣金;4-用户中奖
 */
export const getBusCashFlowListAPI = (userId: string) => {
  return http<CashFlowEntityItem[]>({
    method: 'GET',
    url: `/admin/businessApi/busCashFlowList`,
    data: {
      flowType: '1,2,4,7',
      userId,
    },
  })
}
